package cn.org.xiaoweiba.graduationdesign.bookmall.dto.result;


import cn.org.xiaoweiba.graduationdesign.bookmall.enums.ResponseCodeEnum;
import cn.org.xiaoweiba.graduationdesign.bookmall.utils.StringUtil;

/**
 * 用于封装由于服务端导致的失败响应结果的响应结果类
 */
public class ServerErrorResponseResult extends BaseResponseResult {

    /**
     * 由于服务端导致的失败响应
     *
     * @return 失败响应对象
     */
    public static BaseResponseResult<Object> errorResult() {
        return new BaseResponseResult<>(ResponseCodeEnum.SERVER_ERROR.getCode(), ResponseCodeEnum.SERVER_ERROR.getMessage());
    }

    /**
     * 由于服务端导致的失败响应
     *
     * @param errorMessage 失败响应信息
     * @return 失败响应对象
     */
    public static BaseResponseResult<Object> errorResult(String errorMessage) {
        BaseResponseResult<Object> baseResponseResult = errorResult();
        if (!StringUtil.isNull(errorMessage)) baseResponseResult.setMessage(errorMessage);
        return baseResponseResult;
    }

    /**
     * 由于服务端导致的失败响应
     *
     * @param data 响应数据
     * @return 失败响应对象
     */
    public static BaseResponseResult<Object> errorResult(Object data) {
        BaseResponseResult<Object> baseResponseResult = errorResult();
        if (data != null) baseResponseResult.setData(data);
        return baseResponseResult;
    }

    /**
     * 由于服务端导致的失败响应
     *
     * @param message 失败响应信息
     * @param data    响应数据
     * @return 失败响应对象
     */
    public static BaseResponseResult<Object> errorResult(String message, Object data) {
        BaseResponseResult<Object> baseResponseResult = errorResult();
        if (!StringUtil.isNull(message)) baseResponseResult.setMessage(message);
        if (data != null) baseResponseResult.setData(data);
        return baseResponseResult;
    }

}
